Repository navigation
DEV-1148: consume a bare ACK's link CRC while streaming - #121
Merged
Merged
Conversation
src/test had no JUnit dependency, so nothing in the library could be tested on the JVM. Add JUnit 4 and have the stub android.jar return defaults: Shimmer's constructor and its logging call into it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With a Bluetooth link CRC on, the firmware sends a CRC after a bare ACK too, so a SET command's reply while streaming is FF F4 65, or FF F4 with a 1-byte CRC. Shimmer.processPacket() overrides the driver's parser and took the F4 for a parse error: it threw away the data packet before the ACK a byte at a time, never processed the ACK, and 2 s later the ACK timer cleared the instruction queue. startSDLogging() on a streaming device therefore never sent START_LOGGING_ONLY_COMMAND. Port DEV-1147's driver fix to the override. When the bytes after the ACK are the bare ACK's CRC, wait for all of it, pass the packet on if its own CRC checks out, consume the packet, the ACK and its CRC exactly once (keeping later bytes and their timestamps), and process the ACK. The bulk-read loop in processWhileStreaming() is unchanged. Also override checkCrc() so it only checks. On the pinned driver (0.11.7_beta) it skips to the next frame itself when a 2-byte CRC fails on its second byte, and processPacket() then discarded a byte more: the start of the next packet. AAPI_00002_StreamingBareAckCrcTest ports the driver's API_00027_StreamingBareAckCrcTest and replays each scenario with the bytes arriving in reads of every size from 1 to 48. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
marknolan
added a commit
that referenced
this pull request
Oct 4, 2026
ad9aa5c corrected the wrapper claim as of master. This brings it up to DEV-1148 (#121) and fills gaps in the build notes: - checkCrc() is overridden too since DEV-1148, as a stopgap until the driver pin includes DEV-1147. The section said it was the driver's. - readBattery() and readStatusLogAndStream() write straight to the socket while streaming instead of queueing, and processWhileStreaming() reads in bulk where the driver reads a byte at a time. - DEV-1147's driver fix had to be ported here by hand as DEV-1148. That is the consequence a reader needs, so it is now said outright. - The build root's gradle.properties is gitignored, and AGP refuses to build without android.useAndroidX=true. Jetifier has to stay off: it fails on a transitive jackson-core 2.18.2 (class file version 65). - DEV-1148 adds JVM unit tests (JUnit 4, returnDefaultValues). The command that runs them is documented. - "Java 11" was the source and target level. AGP 8 needs Gradle to run on JDK 17 or later. The unit-test setup and the checkCrc() override exist only on #121's branch, so this should merge after #121. Docs only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Hardware check: Classic HIL, with and without this PRThe Android HIL (#128) ran this PR on a Shimmer3 (LogAndStream v1.1.5) over Bluetooth Classic. Phone: Redmi M2101K6G, Android 11. Driver 0.11.9_beta.
This fixes DEV-1148 on hardware, with both CRC modes, including the default 1-byte. Master reproduces the defect with both. The failures that remain don't come from this PR:
Off the bench: merged onto today's master, the 10 new unit tests pass and the library builds against driver 0.11.7_beta and 0.11.9_beta. The Before merging:
🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes DEV-1148. This is the Android half of DEV-1147 (ShimmerResearch/Shimmer-Java-Android-API#319).
Defect
Shimmer.javaoverrides the driver's streaming parser (processPacket(),processWhileStreaming(),processInstreamResponse()andclearSingleDataPacketFromBuffers()), so a driver bump alone does not help.FF F4 65, orFF F4with a 1-byte CRC. The override took theF4for a parse error ("Unknown parsing error while streaming") and then discarded one byte at a time ("Packet syncing problem") until it reached the next packet:ShimmerBluetoothManagerAndroid.startLogging()accepts a STREAMING device.startSDLogging()queues SET_RWC and then START_LOGGING_ONLY. The RTC write's ACK is lost, and the timeout clears the queue.[SET_RWC, START_LOGGING_ONLY]to[], andisSDLogging()stayed false.initializeShimmer3or3R()sets a 1-byte CRC on firmware version code 8 or later.checkCrc()skips to the next frame itself when a 2-byte CRC fails on its second byte. The override then discarded one more byte, the start of the next packet, so that packet was lost as well.Fix
processPacket(), data packet followed by an ACK. When the bytes after the ACK are the bare ACK's CRC (isBareAckCrcSoFar(), checked againstBARE_ACK_CRC), it waits for the whole CRC and then:clearSingleDataPacketFromBuffers()already works this way);processAckWhileStreaming(), shared with the no-CRC path, which is otherwise unchanged).checkCrc()only checks. It is overridden as DEV-1147 changes the driver's version. Once the driver pin includes DEV-1147, the override can go.processWhileStreaming()is unchanged.BARE_ACK_CRC,isBareAckCrcSoFar()andprocessAckWhileStreaming().Testing
First commit: a local unit-test setup.
src/testhad no JUnit, so nothing in the library could run on the JVM.src/androidTestholds only a Shimmer2R device test, which calls aShimmer(Handler)constructor that no longer exists.New
AAPI_00002_StreamingBareAckCrcTest(10 tests). It ports the driver'sAPI_00027_StreamingBareAckCrcTest. It drives the realShimmerthrough a subclass that replaces only the socket.processWhileStreaming()reads whatever has arrived, so each bare-ACK scenario is replayed with the bytes arriving in reads of every size from 1 to 48 bytes, the last being all at once.Proof the tests catch the bug.
checkCrc()override removed, exactly the 2 tests with a 2-byte CRC failing on its second byte fail.F4 65was checked against an independent implementation of the CRC.Full runs (Gradle 8.5 wrapper, JDK 21):
./gradlew -Pandroid.useAndroidX=true :ShimmerAndroidInstrumentDriver:test:ShimmerAndroidInstrumentDriver:assembleDebug assembleReleaseRunning the tests. The build root's
gradle.propertiesis gitignored. It needsandroid.useAndroidX=true, as it did when it was tracked. If yours also setsandroid.enableJetifier=true, addandroid.jetifier.ignorelist=jackson-core: Jetifier cannot read jackson-core 2.18.2's Java 21 classes on the unit-test classpath.Not fixed here: in-stream defects found while porting
In-stream responses (
FF 8A …) have defects of their own in this override. This PR leaves them alone. Each was reproduced with throwaway tests, not committed.processInstreamResponse()checks for the response without its CRC.clearSingleDataPacketFromBuffers()then refuses to clear past the end of the buffer.readBattery()andreadStatusLogAndStream()write straight to the socket instead of queueing. The in-stream branch still runsremoveInstruction(0), cancels the ACK timer and unlocks the queue.processAckFromSetCommand()throwsArrayIndexOutOfBoundsExceptionon the IO thread.processInstreamResponse(). That version reads the response from the socket instead of from the bytes already buffered.These need a ticket of their own.
Siblings and docs (CLAUDE.md §4)
Shimmer.javais the only parser: neitherShimmer4AndroidnorVerisenseDeviceAndroidoverrides it.Shimmer.javacontradicts both, and that is how DEV-1147 missed Android.Not verified on hardware
No device has been run against this. To check on one:
startLogging(), for example from bluetoothManagerExample.🤖 Generated with Claude Code